package com.buke66.taoduo.goods.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.buke66.taoduo.goods.entity.GoodsCategoryEntity;
import com.buke66.taoduo.goods.service.GoodsCategoryService;
import com.buke66.taoduo.common.utils.PageUtils;
import com.buke66.taoduo.common.utils.R;



/**
 * 商品三级分类
 *
 * @author buke
 * @email 66482504@qq.com
 * @date 2021-10-06 10:22:31
 */
@RestController
@RequestMapping("goods/goodscategory")
public class GoodsCategoryController {
    @Autowired
    private GoodsCategoryService goodsCategoryService;

    /**
     * 查出所有分类以及子分类，以树型结构组装
     */
    @RequestMapping("/list/tree")
        public R list(){

        List<GoodsCategoryEntity> entitysListTree = goodsCategoryService.listWithTree();
        return R.ok().put("data", entitysListTree);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{catId}")
        public R info(@PathVariable("catId") Long catId){
		GoodsCategoryEntity goodsCategory = goodsCategoryService.getById(catId);

        return R.ok().put("goodsCategory", goodsCategory);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
        public R save(@RequestBody GoodsCategoryEntity goodsCategory){
		goodsCategoryService.save(goodsCategory);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
        public R update(@RequestBody GoodsCategoryEntity goodsCategory){
		goodsCategoryService.updateById(goodsCategory);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
        public R delete(@RequestBody Long[] catIds){
		// goodsCategoryService.removeByIds(Arrays.asList(catIds));
		goodsCategoryService.removeCategoryByIds(Arrays.asList(catIds));
        return R.ok();
    }

}
